// pages/read/read.ts
const {handleStr,handleStar,http} = require("../../utils/util.js");
Page({
  data: {
    movies:Array,
  },
  onLoad() {
    wx.request({
      url:"http://47.108.197.28:4000/api/movie/top250",
      header:{"content-type":"application/json"},
      method:"GET",
      responseType:"text",
      success:(res:Object)=>{
        let movies:Array<Object> = [];
        this.handleHttpData(res.data.res,movies);
        this.setData({movies})
      }  
    })
  },
  handleHttpData(res:Array<object>,arr:Array<object>){
    res.forEach((item:any)=>{
      let {_id,pic,title,rating} = item;
      title = handleStr(title);
      let star = handleStar(rating);
      arr.push({_id,pic,title,rating:parseFloat(rating),star});
    });
    return arr;
  },
  onTap(event:Object){
    var id:String = event.currentTarget.dataset.aid;
    wx.navigateTo({
      url: `/pages/detail/detail?id=${id}`,
    })
  },
})